package com.atguigu.speingcloud.controller;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

@RestController
@Slf4j
@RefreshScope//配置的动态刷新
public class OrderNacosController {

    @Autowired
    private RestTemplate restTemplate;

    /*此配置是从nacos配置中心读取的*/
    @Value("${service-url.nacos-consumer-service}")
    private String SERVICE_URL;

    @GetMapping(value = "/consumer/payment/nacos/{id}")
    public String getPayment(@PathVariable("id") Integer id){
        return restTemplate.getForObject(SERVICE_URL+"/payment/nacos/"+id,String.class);
    }

    @GetMapping("/get/nacos/config")
    public String getconfig(){
        return "service name is "+SERVICE_URL;
    }
}
